package com.asm.slidingmenu.adapter;

import java.util.ArrayList;

import com.asm.DBloader.ASM_AVTemp;
import com.asm.DBloader.ASM_AVTempDS;
import com.asm.DBloader.ASM_FAvDet;
import com.asm.DBloader.ASM_fItems;
import com.asm.DBloader.ASM_fItemsDS;
import com.dspl.asmswd.R;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class AVSheetAdapter extends ArrayAdapter<ASM_AVTemp> {
	Context context;
	public static ArrayList<ASM_AVTemp> list;
	
	
	public AVSheetAdapter(Context context, ArrayList<ASM_AVTemp> list) {
		super(context, R.layout.asm_avsheet_det, list);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.list = list;
		
	}
	@Override
	public View getView(final int position, final View convertView, final ViewGroup parent) {
		
		LayoutInflater inflater = null;
		View row = null;
		
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		row = inflater.inflate(R.layout.asm_avsheet_det, parent, false);

		final Button Itemcode = (Button) row.findViewById(R.id.itemcode);
		final EditText status = (EditText) row.findViewById(R.id.status);
		final EditText newsale = (EditText) row.findViewById(R.id.newsale);
		final EditText uitem = (EditText) row.findViewById(R.id.uitem);
		final EditText ustatus = (EditText) row.findViewById(R.id.ustatus);
		final EditText hitem = (EditText) row.findViewById(R.id.hitem);
		final EditText hstatus = (EditText) row.findViewById(R.id.hstatus);
		final EditText vitem = (EditText) row.findViewById(R.id.vitem);
		final EditText vstatus = (EditText) row.findViewById(R.id.vstatus);
		
		
		Itemcode.setText(list.get(position).getAsmavTempItemname()+"-:-"+list.get(position).getAsmavTempItemcode());
		
		//status.setSel
		newsale.setText(list.get(position).getAsmavTempNewsales());
		uitem.setText(list.get(position).getAsmavTempUitems());
		hitem.setText(list.get(position).getAsmavTempHitems());
		vitem.setText(list.get(position).getAsmavTempVitems());
		status.setText(list.get(position).getAsmavTempStatus());
		ustatus.setText(list.get(position).getAsmavTempUstatus());
		hstatus.setText(list.get(position).getAsmavTempHstatus());
		vstatus.setText(list.get(position).getAsmavTempVstatus());
		

		status.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) 
			{
				
				if(status.getText().toString().toUpperCase().equals("A")||status.getText().toString().toUpperCase().equals("N")||
		    			status.getText().toString().toUpperCase().equals("D")||status.getText().toString().toUpperCase().equals("AD"))
		    	{
		    		Toast.makeText(context, "OK",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempStatus(status.getText().toString());

		    	}
				else 
		    	{
					Toast.makeText(context, "Please Use Only A,N,D,AD",Toast.LENGTH_LONG).show();
					list.get(position).setAsmavTempStatus(status.getText().toString());
				}
				ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){
		    }
		    public void onTextChanged(CharSequence s, int start, int before, int count)
		    {
		    }
		});

		
		
		newsale.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
			
				
				list.get(position).setAsmavTempNewsales(newsale.getText().toString());
	    		ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});
		
		
		

		uitem.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
			
				list.get(position).setAsmavTempUitems(uitem.getText().toString());
	    		ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});
		
		ustatus.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
			
				if(ustatus.getText().toString().toUpperCase().equals("A")||ustatus.getText().toString().toUpperCase().equals("N")||
						ustatus.getText().toString().toUpperCase().equals("D")||ustatus.getText().toString().toUpperCase().equals("AD"))
		    	{
		    		Toast.makeText(context, "OK",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempUstatus(ustatus.getText().toString());
		    		
		    		
		    	}else 
		    	{
		    		Toast.makeText(context, "Please Use Only A,N,D,AD",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempUstatus(ustatus.getText().toString());
				}
				ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});
		
		

		
		hitem.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
			
				list.get(position).setAsmavTempHitems(hitem.getText().toString());
	    		ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});
		
		hstatus.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
			
				if(hstatus.getText().toString().toUpperCase().equals("A")||hstatus.getText().toString().toUpperCase().equals("N")||
						hstatus.getText().toString().toUpperCase().equals("D")||hstatus.getText().toString().toUpperCase().equals("AD"))
		    	{
		    		Toast.makeText(context, "OK",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempHstatus(hstatus.getText().toString());
		    		
		    		
		    	}else 
		    	{
		    		Toast.makeText(context, "Please Use Only A,N,D,AD",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempHstatus(hstatus.getText().toString());
				}
				ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
				
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});

		
		
		vitem.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
			
				list.get(position).setAsmavTempVitems(vitem.getText().toString());
	    		ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});
		
		vstatus.addTextChangedListener(new TextWatcher(){
			public void afterTextChanged(Editable s) {
				if(vstatus.getText().toString().toUpperCase().equals("A")||vstatus.getText().toString().toUpperCase().equals("N")||
						vstatus.getText().toString().toUpperCase().equals("D")||vstatus.getText().toString().toUpperCase().equals("AD"))
		    	{
		    		Toast.makeText(context, "OK",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempVstatus(vstatus.getText().toString());
		    		
		    		
		    	}else 
		    	{
		    		Toast.makeText(context, "Please Use Only A,N,D,AD",Toast.LENGTH_LONG).show();
		    		list.get(position).setAsmavTempVstatus(vstatus.getText().toString());
				}
				ASM_AVTempDS DS5 = new ASM_AVTempDS(context);
				DS5.Create(AVSheetAdapter.list);
	
		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		});
		
		
		
		return row;
	}
}
